<template>
    <MyDialog :model-value="true" :type="DialogType.C2" title="专家评估" @close="onClose">
        <el-form ref="UserDetailFormRef" label-width="150" :model="thisData">
            <el-row>
                <el-col :span="8">
                    <el-form-item label="初始小破断力" prop="loginName">
                        <InputNumber v-model="thisData.originKn" :disabled="isSee"></InputNumber>
                    </el-form-item>
                </el-col>

                <el-col :span="8">
                    <el-form-item label="实测最小破断力" prop="loginName">
                        <InputNumber v-model="thisData.minKn" :disabled="isSee"></InputNumber>
                    </el-form-item>
                </el-col>

                <el-col :span="8">
                    <el-form-item label="最小破断损失百分比" prop="loginName">
                        <InputNumber v-model="thisData.minKnPercent" :disabled="isSee"></InputNumber>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-form-item label="拆股试验报告" prop="loginName">
                <MyUpload v-model="thisData.attr1_FilesList" :disabled="isSee"></MyUpload>
            </el-form-item>

            <el-form-item label="破断试验报告" prop="loginName">
                <MyUpload v-model="thisData.attr2_FilesList" :disabled="isSee"></MyUpload>
            </el-form-item>

            <el-form-item label="评估报告" prop="loginName">
                <MyUpload v-model="thisData.attr3_FilesList" :disabled="isSee"></MyUpload>
            </el-form-item>

            <el-form-item label="专家评估建议" prop="loginName">
                <MyUpload v-model="thisData.attr4_FilesList" :disabled="isSee"></MyUpload>
            </el-form-item>
        </el-form>

        <template #footer>
            <el-button type="primary" :loading="loading" @click="onSave" v-if="!isSee">提交</el-button>
        </template>
    </MyDialog>
</template>

<script setup lang="ts">
import Gx from "@/gx/Gx";
import { DialogType, TipsType } from "@/_gx/TsEnums";

//接收父组件的传值
const usingWireropeID = inject("usingWireropeID") as Ref<number | null>;

//定义当前页面数据对象
const thisData = ref<any>({
    attr1_FilesList: [],
    attr2_FilesList: [],
    attr3_FilesList: [],
    attr4_FilesList: [],
});

//loading...
const loading = ref(false);
//查看
const isSee = ref(false);

//初始化
const Init = (_isSee: boolean = false) => {
    isSee.value = _isSee;

    if (!Gx.IsEmpty(usingWireropeID.value)) {
        App.CallApi(Api.UsingWirerope.GetByID(usingWireropeID.value), {
            success: (res) => {
                thisData.value = res;
            },
        });
    }
};

//保存
const onSave = () => {
    loading.value = true;
    App.CallApi(Api.UsingWirerope.UpdateZuoFeiInfo, {
        data: thisData.value,
        success: () => {
            App.Tips({ type: TipsType.Success, msg: "保存成功！" });
            emits("close", true);
        },
        complete: () => {
            loading.value = false;
        },
    });
};

const onClose = () => {
    emits("close", false);
};

const emits = defineEmits(["close"]);
defineExpose({ Init });
</script>
